package Algorithm;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Day07 {

    public static void main1(String[] args) {
        String ransomNote = "aa";
        String magazine = "aab";
        int len1 = ransomNote.length();
        int len2 = magazine.length();
        if(len1 > len2) {
            System.out.println("false");
        }

        int[] maga = new int[26];
        for(int i = 0; i < len2; i++) {
            maga[magazine.charAt(i) - 'a'] += 1;
        }

        for(int i = 0; i < len1; i++) {
            maga[ransomNote.charAt(i) - 'a'] -= 1;
        }

        for(int count: maga) {
            if(count != 0) {
                System.out.println("false");
                return;
            }
        }
        System.out.println("true");
    }

    public static void main(String[] args) {

        int[] nums = {-1,0,1,2,-1,-4,-2,-3,3,0,4};
        List<List<Integer>> res = new ArrayList<>();
        Arrays.sort(nums);
        for(int i = 0; i < nums.length; i++) {

            if(nums[i] > 0) {
                return;
            }
            if(i > 0 && nums[i] == nums[i-1]) {
                continue;
            }

            int left = i + 1;
            int right = nums.length - 1;
            while(left < right) {
                List<Integer> list = new ArrayList<>();
                if(nums[i] + nums[left] + nums[right] > 0) {
                    right--;
                } else if(nums[i] + nums[left] + nums[right] < 0) {
                    left++;
                } else {
                    list.add(nums[i]);
                    list.add(nums[left]);
                    list.add(nums[right]);
                    res.add(list);
                    left++;
                    right--;
                }

                if(nums[left] == nums[left-1]) {
                    left++;
                }
                if(nums[right] == nums[right-1]) {
                    right--;
                }
            }
        }

    }
}
